//
//  AppController.h
//  operator
//
//  Created by Andrej on 21.12.11.
//  Copyright (c) 2011 RWTH Aachen. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <MapKit/MapKit.h>
#import "ClientThreadController.h"
#import "ClientMessaging.h"
#import "NetworkingCenter.h"
#import "NetworkMessage.h"
#import "NetworkMessageCreator.h"
#import "GameState.h"
#import "Located.h"
#import "MapIcon.h"
#import "MapIconView.h"
#include "Team.h"
#include "Hunter.h"
#include "Runner.h"
#include "Checkpoint.h"

@interface AppController : NSWindowController<MKMapViewDelegate, NSTableViewDelegate> {
    GameState *state;
  
    /* login */
    IBOutlet NSTextField *userTextField;
    IBOutlet NSMatrix *teamChoose;

    /* map view */
    IBOutlet MKMapView *mapView;

    /* the overlay view on top of the map view for drawing stuff */
    IBOutlet NSView *overlayView;

    /* panels */
    IBOutlet NSPanel *statusPanel;
    IBOutlet NSPanel *statusTeamPanel;

    /* information tabels within the status panel */
    IBOutlet NSTableView *teamTable;
    IBOutlet NSTableView *checkpointTable;

    /* data for information tables (objects of class MapIcon) */
    NSMutableArray *teamMemberPanel;
    NSMutableArray *checkpointPanel;

    /* cocoa binding for information tables */
    IBOutlet NSArrayController *memberController;
    IBOutlet NSArrayController *checkpointController;
}

/*
 * Returns the key for the MapIcon object in state.mapAnnotations dictionary 
 * which is located at the position under the mouse click.
 * If there is no such object, the method will return nil.
 * (Note: Bases and enemy hunters are excluded)
 */
-(NSString*) getAnnotationLocatedAt:(NSPoint)p;

/*
 * Checks if annotationId is a key for a MapIcon object in state.mapAnnotations
 */
-(bool) isAnnotationIdValid:(NSString*)annotationId;

/*
 * For an annotationId which is a key for a MapIcon object in state.mapAnnotations,
 * the transformation from latitude, longitude coordinates to screen coordinates
 * is done. Returns (0, 0) if the key is not valid.
 */
-(NSPoint) getAnnotationLocation:(NSString*)annotationId;

/*
 * Sends an assign message to the server if the binding of the corresponding game
 * objects (runners, hunters, checkpoints) is valid and returns true.
 * Otherwise the method returns false.
 */
-(bool) setBindingFrom:(NSString*)annotationId1 To:(NSString*)annotationId2;

/*
 * Sends an unassign message to the server if there exist a binding for the 
 * corresponding game object (runner, hunter) and returns true.
 * Otherwise the method retruns false.
 */
-(bool) unsetBindingOf:(NSString*)annotationId;

/*
 * Returns true if the binding from the game object corresponding to annotationId1
 * to the game object corresponding to annotationId2 (or vice-versa) is valid.
 * Otherwise the method returns false.
 */
-(bool) isValidBindingBetween:(NSString*)annotationId1 And:(NSString*)annotationId2;

-(IBAction) login:(id)sender;
-(IBAction) togglePanels:(id)sender;
-(IBAction) gotoBase:(id)sender;

@property(retain)  NSMutableArray *teamMemberPanel;
@property(retain)  NSMutableArray *checkpointPanel;

@end
